function JoinRoomPerson() {
	thisJoinRoomPerson = this;

	this.TAG = " < JoinRoomPerson > ";
	this.joinRoomSeq = null;
	
	/**
	 * 참여자 리스트
	 */
	this.memberList = null;
	
	/**
	 * 신청자 리스트
	 */
	this.applyMemberList = null;
	
	this._HTMLDom = null;
}

JoinRoomPerson.prototype = {
		goProfile: function($userId, $nickName) {
			console.log(this.TAG + "goProfile()");

			document.globalObj.PROFILE_DATA.userId = $userId;
			document.globalObj.PROFILE_DATA.nickName = $nickName;

			$.mobile.changePage("../mypage/profile_view.html");
		},
		/**
		 * 신청자 리스트
		 */
		getApplyMemberList: function() {
			console.log(this.TAG + "getApplyMemberList()");
			
			var mJson = new MJson();
			mJson.putClient(MJson.CLIENT.USERID, document.globalObj.LOGIN_DATA.userId);
			mJson.putPub(MJson.PUB.SID, "JR001");
			mJson.putPub(MJson.PUB.SERVICENAME, "getApplyMemberList");
			mJson.putPub(MJson.PUB.LISTCOUNT, "");
			mJson.putPub(MJson.PUB.CURRPAGENO, "");
			
			mJson.putParameter(MJson.PARAMETER.JOINROOMSEQ, this.joinRoomSeq);
			
			var cm = new ConnectionManager();
			//_util.ajaxLog(mJson.getJsonString());
			cm.requestGet(mJson.getJsonString(), function(jsonData) {
				//console.log(thisJoinRoomPerson.TAG + JSON.stringify(jsonData));
				if(jsonData.msp.result.code === "00000")
				{
					if(jsonData.msp.contents.items) 
					{
						if(!jsonData.msp.contents.items.length)
						{
							thisJoinRoomPerson.applyMemberList.push(jsonData.msp.contents.items);
						}
						else
						{
							for(var i=0; i<jsonData.msp.contents.items.length; i++)
							{
								thisJoinRoomPerson.applyMemberList.push(jsonData.msp.contents.items[i]);
							}
						}
						//thisJoinRoomPerson.viewApplyMemberList();
					}
					
					thisJoinRoomPerson.viewApplyMemberList();
				}
				else
					alert("error code:"+jsonData.msp.result.code);
				
			}, function(e){
				alert("error:"+JSON.stringify(e));
			})
		},
		/**
		 * 참여자 리스트
		 */
		getMemberList: function() {
			console.log(this.TAG + "getMemberList()");
			
			var mJson = new MJson();
			mJson.putClient(MJson.CLIENT.USERID, document.globalObj.LOGIN_DATA.userId);
			mJson.putPub(MJson.PUB.SID, "JR001");
			mJson.putPub(MJson.PUB.SERVICENAME, "getMemberList");
			mJson.putPub(MJson.PUB.LISTCOUNT, "");
			mJson.putPub(MJson.PUB.CURRPAGENO, "");
			
			mJson.putParameter(MJson.PARAMETER.JOINROOMSEQ, this.joinRoomSeq);
			
			var cm = new ConnectionManager();
			//_util.ajaxLog(mJson.getJsonString());
			cm.requestGet(mJson.getJsonString(), function(jsonData) {

				//console.log(thisJoinRoomPerson.TAG + JSON.stringify(jsonData));
				
				if(jsonData.msp.result.code === "00000")
				{
					
					if(jsonData.msp.contents.items) 
					{
						if(!jsonData.msp.contents.items.length)
						{
							thisJoinRoomPerson.memberList.push(jsonData.msp.contents.items);
						}
						else 
						{
							for(var i=0; i<jsonData.msp.contents.items.length; i++)
							{
								//console.log(jsonData.msp.contents.items[i]);
								thisJoinRoomPerson.memberList.push(jsonData.msp.contents.items[i]);
							}
						}
						
						//thisJoinRoomPerson.viewMemberList();
						
					}
					
					thisJoinRoomPerson.viewMemberList();
					
				}
				else
					alert("error code:"+jsonData.msp.result.code);
				
			}, function(e){
				alert("error:"+JSON.stringify(e));
			})
		},
		init: function() {
			console.log(this.TAG + "init()");
			this.joinRoomSeq = document.globalObj.joinRoomSeq;
			this.memberList = new Array();
			this.applyMemberList = new Array();
			
			this.getMemberList();
			
			this.getApplyMemberList();
			
			//this.initEvent();
		},
		initEvent: function() {
			console.log(thisJoinRoomPerson.TAG + "initEvent()");
			
			var updownBtns = $(".updown_bt").find("button");
			
			updownBtns.unbind("click");
			updownBtns.bind("click", function($event){
				var type = $(this).attr("id").split("_")[1]; // 취소:cancel, 승인:confirm
				
				console.log("버튼종류:"+type);
				
				if(type === "cancel") {
					console.log(thisJoinRoomPerson.TAG + "참여취소!!");
					var deleteMember = new DeleteMember(thisJoinRoomPerson.joinRoomSeq, thisJoinRoomPerson.memberList, thisJoinRoomPerson);
					deleteMember.req();
				}else {
					console.log(thisJoinRoomPerson.TAG + "참여승인!!");
					var updateMember = new UpdateMember(thisJoinRoomPerson.joinRoomSeq, thisJoinRoomPerson.applyMemberList, thisJoinRoomPerson);
					updateMember.req();
				}
					
			});
		},
		onPageShow: function() {
			console.log(this.TAG + "onPageShow()");
            this._HTMLDom = {
                "member_list" : $("#person_member_listview"), // 신청자 리스트뷰
                "member_list_item" : $("#person_member_listview").find('li:first').clone(true), // 참여자, 신청자 리스트 아이템 
                "apply_member_list" : $("#person_apply_member_listview"), // 참여자 리스트뷰
            };
			this.init();
		},
		/**
		 * 조인룸 신청자 리스트
		 */
		viewApplyMemberList: function() {
			console.log(this.TAG + "viewApplyMemberList()");
			
			var listview = this._HTMLDom.apply_member_list;
			var item = this._HTMLDom.member_list_item;
            
			$(".person_take:eq(1)>h3>span").html(this.applyMemberList.length+"명");			
			
			listview.empty();
			console.log("신청자 리스트");
			console.log(this.applyMemberList);
			var img = "../images/noimg_100_100.gif";
			var list = this.applyMemberList;
			var util = new Util();
			
			for (var i=0; i < list.length; i++)
			{
				var data = list[i];
				
				var temp = item.clone(true);
				
				listview.append(temp);
				
				temp.attr("id", "apply_member_"+i);
				temp.find("input:checkbox, label").remove(); // label과 input은 쌍임으로 함께 지워준다.
				temp.find("ul").after("<label><input type='checkbox' name=apply_member_checkbox_"+i+" /></label>"); // 다시 생성해준다.
				temp.find("input:checkbox").checkboxradio(); // checkboxradio에 인자가 없는것은 초기화해준다는 의미임ㅋ
				temp.find("a").attr("href", "#");
				temp.find("a>img").attr("src", data.saveFileNm?(util.filePath2Url(data.path)+data.saveFileNm):img);
				//temp.find("h5").html(data.nickName);
				//temp.find("a").after("<h5 id="+i+">"+data.nickName+"</h5>");
				temp.find("h5").attr("id", i);
				temp.find("h5").html(data.nickName);//.attr("id", i);
				temp.find("ul>li:first>span").attr("class", data.sex === "남"? "sex_m":"sex_w").html(data.sex);
				temp.find("ul>li:eq(1)").html(data.regionNm == undefined?"수도권(서울/경기/인천)":data.regionNm);
				temp.find("ul>li:eq(2)").html((data.age == undefined?"20":data.age));// + "대");
				temp.find("ul>li:eq(3)").html("핸디 : " + (data.handi == undefined?"50":data.handi));
				temp.find("ul>li:eq(4)").html("평균타수 : " + (data.aVerage == undefined?"100":data.aVerage));
				
				//"<a data-transition=slide><img src="+ (data.saveFileNm?(util.filePath2Url(data.path)+data.saveFileNm):"../images/noimg_100_100.gif")+" alt=''/></a>");
			}
			
			/*
			 * 프로필 보기.
			 */
			listview.find("h5").unbind("click");
			listview.find("h5").bind("click", function($event){
				console.log($(this).attr("id"));
				var id = $(this).attr("id");
				var data = list[id];
				//console.log(data);
				//thisJoinRoomPerson.goProfile(data);
				thisJoinRoomPerson.goProfile(data.participantId, data.nickName);
			});

			this.initEvent();
		},
		/**
		 * 조인룸 참여자 리스트
		 */
		viewMemberList: function()
		{
			console.log(this.TAG + "viewMemberList()");
			
			var listview = this._HTMLDom.member_list;
			var item = this._HTMLDom.member_list_item;
            
			listview.empty();
			
			console.log("참여자 리스트");
			console.log(this.memberList);
			
			$(".person_take:eq(0)>h3>span").html("<mark>"+this.memberList.length+"명</mark>"+" / 5명");
			
			console.log("참여자 수:"+this.memberList.length);
			
			var img = "../images/noimg_100_100.gif";
			var util = new Util();
			for (var i=0; i < this.memberList.length; i++)
			{
				
				var temp = item.clone(true);
				listview.append(temp);
				
				var data = this.memberList[i];
				temp.attr("id", "member_"+i);
				temp.find("input:checkbox, label").remove(); // label과 input은 쌍임으로 함께 지워준다.
				temp.find("ul").after("<label><input type='checkbox' name=cancel_member_checkbox_"+i+" /></label>"); // 다시 생성해준다.
				temp.find("input:checkbox").checkboxradio(); // checkboxradio에 인자가 없는것은 초기화해준다는 의미임ㅋ
				temp.find("a").attr("href", "#");
				temp.find("a>img").attr("src", data.saveFileNm?(util.filePath2Url(data.path)+data.saveFileNm):img);
				temp.find("h5").attr("id", i);
				temp.find("h5").html(data.nickName);
				temp.find("ul>li:first>span").attr("class", data.sex === "남"? "sex_m":"sex_w").html(data.sex);
				temp.find("ul>li:eq(1)").html(data.regionNm == undefined?"수도권(서울/경기/인천)":data.regionNm);
				temp.find("ul>li:eq(2)").html((data.age == undefined?"20":data.age));// + "대");
				temp.find("ul>li:eq(3)").html("핸디 : " + (data.handi == undefined?"50":data.handi));
				temp.find("ul>li:eq(4)").html("평균타수 : " + (data.aVerage == undefined?"100":data.aVerage));
			}
			
			/*
			 * 프로필 보기.
			 */
			listview.find("h5").unbind("click");
			listview.find("h5").bind("click", function($event){
				console.log($(this).attr("id"));
				var id = $(this).attr("id");
				var data = list[id];
				//console.log(data);
				//thisJoinRoomPerson.goProfile(data);
				thisJoinRoomPerson.goProfile(data.participantId, data.nickName);
			});
		}
}

/**
 * @param $joinRoomSeq 조인룸 번호
 * @param $applyMemberList 신청자 리스트
 * @param $context
 */
function UpdateMember($joinRoomSeq, $applyMemberList, $context)
{
	thisUpdateMember = this;
	this.TAG = " < UpdateMember > ";
	console.log(this.TAG + "UpdateMember Class");
	this.joinRoomSeq = $joinRoomSeq;
	this.context = $context;
	this.applyMemberList = $applyMemberList;
	this.participantIdList = this.getParticipantIdList()[0]; // array
	this.joinRoomSeqList = this.getParticipantIdList()[1];
}

UpdateMember.prototype = {
		getParticipantIdList: function() {
			console.log(this.TAG + "getParticipantId()");
			
			var listview = $("#person_apply_member_listview");
			var boxList = listview.find("input[type=checkbox]:checked");
			var participantIdList = new Array();
			var joinRoomSeqList = new Array();
			for(var i=0; i<boxList.length; i++) 
			{
				var position = boxList.eq(i).attr("name").split("_")[3];
				participantIdList.push(this.applyMemberList[position].participantId);
				joinRoomSeqList.push(this.applyMemberList[position].joinRoomSeq + "");
			}

			return new Array(participantIdList, joinRoomSeqList);
		},
		req: function()
		{
			if(this.applyMemberList.length == 0 || this.participantIdList.length == 0) return alert("리스트가 없거나, 체크하지 않았습니다.")
			var mJson = new MJson();
			mJson.putClient(MJson.CLIENT.USERID, document.globalObj.LOGIN_DATA.userId);
			mJson.putPub(MJson.PUB.SID, "JR001");
			mJson.putPub(MJson.PUB.SERVICENAME, "updateMember");
			mJson.putPub(MJson.PUB.LISTCOUNT, "");
			mJson.putPub(MJson.PUB.CURRPAGENO, "");
			
			mJson.putParameter(MJson.PARAMETER.PARTICIPANTID, this.participantIdList.join(","));
			mJson.putParameter(MJson.PARAMETER.JOINROOMSEQ, this.joinRoomSeqList.join(","));
			console.log(mJson.getJsonString());
			var cm = new ConnectionManager();
			cm.requestGet(mJson.getJsonString(), function(jsonData){
				if(jsonData.msp.result.code === "00000") 
				{
					thisUpdateMember.context.init();
				}
			}, function(e){
				
				alert("error:"+JSON.stringify(e));
				
			})
		}
}

/**
 * @param $joinRoomSeq 조인룸 번호
 * @param $nemberList 신청자 리스트
 * @param $context
 */
function DeleteMember($joinRoomSeq, $memberList, $context)
{
	thisDeleteMember = this;
	this.TAG = " < DeleteMember > ";
	console.log(this.TAG + "DeleteMember Class");
	this.joinRoomSeq = $joinRoomSeq;
	this.context = $context;
	this.memberList = $memberList;
	this.participantIdList = this.getParticipantIdList()[0];  // array;
	this.joinRoomSeqList = this.getParticipantIdList()[1];
	
	console.log(this.participantIdList);
	console.log(this.joinRoomSeqList);
}

DeleteMember.prototype = {
		getParticipantIdList: function() {
			console.log(this.TAG + "getParticipantId()");
			
			var listview = $("#person_member_listview");
			var boxList = listview.find("input[type=checkbox]:checked");
			var participantIdList = new Array();
			var joinRoomSeqList = new Array();
			for(var i=0; i<boxList.length; i++) 
			{
				var position = boxList.eq(i).attr("name").split("_")[3];
				participantIdList.push(this.memberList[position].participantId);
				joinRoomSeqList.push(this.memberList[position].joinRoomSeq + ""); // --> String으로 전환해줘야 서버에서 인식함? ㅡㅡ; ㅋ
			}
			
			return new Array(participantIdList, joinRoomSeqList);
		},
		req: function()
		{
			console.log(this.TAG + "req()");
			if(this.memberList.length == 0 || this.participantIdList.length == 0) return alert("리스트가 없거나, 체크하지 않았습니다.")
			
			var mJson = new MJson();
			mJson.putClient(MJson.CLIENT.USERID, document.globalObj.LOGIN_DATA.userId);
			mJson.putPub(MJson.PUB.SID, "JR001");
			mJson.putPub(MJson.PUB.SERVICENAME, "deleteMember");
			mJson.putPub(MJson.PUB.LISTCOUNT, "");
			mJson.putPub(MJson.PUB.CURRPAGENO, "");
			
			mJson.putParameter(MJson.PARAMETER.PARTICIPANTID, this.participantIdList.join(","));
			mJson.putParameter(MJson.PARAMETER.JOINROOMSEQ, this.joinRoomSeqList.join(","));

			var cm = new ConnectionManager();
			cm.requestGet(mJson.getJsonString(), function(jsonData){
				console.log(mJson.getJsonString());
				if(jsonData.msp.result.code === "00000") 
				{
					thisDeleteMember.context.init();
				}
			}, function(e){
				alert("error:"+JSON.stringify(e));
			})
		}
}

// 상속 예제
/*function DD(d) {
	this.d = d;
}

DD.prototype = {
		req: function() {
			console.log(this.d);
		}
}

function AA(a){
	DD.apply(this, arguments);
}

AA.prototype = new DD();

*/


